/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.fatecpg.songs.entity;

import br.com.fatecpg.songs.entity.util.Gender;
import br.com.fatecpg.songs.entity.util.Securable;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Marcos
 */
@SequenceGenerator(name="SEQMUSICIAN", sequenceName="SEQMUSICIAN", allocationSize=1, initialValue=1)
@Entity(name="Musician")
@Table(name="TB_MUSICIAN")
public class Musician implements Persistent, Securable{

    public Musician() {
        originCity = new City();
    }
    
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="SEQMUSICIAN")
    @Column(name="id")
    private Long id;
    
    @Column(name = "name")
    private String name;      
    
    @Column(name = "biography")
    private String biography;
    
    @Temporal(TemporalType.DATE)
    @Column(name = "birthday")
    private Date birthday;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "gender")
    private Gender gender;
    
    @ManyToOne
    @JoinColumn(name = "id_origin_city", referencedColumnName = "id")
    private City originCity;   
    
    
    @ManyToMany(mappedBy = "musicians")    
    private List<Artist> artists;
        
    @ManyToMany(mappedBy = "composers")    
    private List<Song> compositions;
            
    @ManyToOne
    @JoinColumn(name = "id_updater", referencedColumnName = "id")
    private User updaterUser;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_update")
    private Date lastUpdate;

    @Override
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getBiography() {
        return biography;
    }

    public void setBiography(String biography) {
        this.biography = biography;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }        

    public City getOriginCity() {
        return originCity;
    }

    public void setOriginCity(City originCity) {
        this.originCity = originCity;
    }

    public List<Artist> getArtists() {
        return artists;
    }

    public void setArtists(List<Artist> artists) {
        this.artists = artists;
    }
    
    public List<Song> getCompositions(){
        return compositions;
    }

    public void setCompositions(List<Song> compositions) {
        this.compositions = compositions;
    }

    @Override
    public User getUpdaterUser() {
        return updaterUser;
    }

    @Override
    public void setUpdaterUser(User updaterUser) {
        this.updaterUser = updaterUser;
    }

    @Override
    public Date getLastUpdate() {
        return lastUpdate;
    }

    @Override
    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }        

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 23 * hash + (int) (this.id ^ (this.id >>> 32));
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Musician other = (Musician) obj;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }        
}
